<?php

/**
 * 后台管理
 * 
 * @author suning <snsnsky@gmail.com>
 */

define('SITE_AUTH', 'home');
require('common.inc.php');


class admin extends lib\core\AdminAction
{
    /**
     * 程序入口
     *
     */
    public function doDefault()
    {
        $auth = $_SESSION['admin_auth_list'];

        $menu = \Admin\Menu::getAllMenu($auth);
        foreach ($menu as $k => $v)
        {
            if (empty($v['child']))
            {
                unset($menu[$k]);
            }
            $child_empty = true;
            foreach ($v['child'] as $k2 => $v2)
            {
                if (!empty($v2['child']))
                {
                    $child_empty = false;
                }
                else
                {
                    unset($menu[$k]['child'][$k2]);
                }
            }
            if ($child_empty)
            {
                unset($menu[$k]);
            }
        }
        $smarty = $this->app->page();
        $smarty->value('menu', $menu);
        $smarty->value('admin', $_SESSION['admin_info']);
        $smarty->value('modules_root', ADMIN_MODULES);
        $smarty->output('admin.tpl');
    }

    public function doRefresh()
    {
        $uid = $_SESSION['admin_info']['AdminUserId'];
        if (empty($uid))
        {
            session_destroy();
            $this->app->redirect('index.php');
        }
        $admin = \Admin\AdminAuth::getAdminUserById($uid);
        $auth = unserialize($admin['SpecialGroups']);
        $group_auth = unserialize($admin['GroupData']['AdminAuth']);
        $auth = array_merge((array)$auth, (array)$group_auth);
        $_SESSION['admin_auth_list'] = array_combine($auth, $auth);
        $_SESSION['admin_info'] = $admin;
        exit();
    }
}
$app->run();

?>